#include <dirent.h>
#include <vector>
#include <sys/stat.h>
#include <string>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <unistd.h>

using namespace std;

void checkDirectory(DIR *t, int spaces){
    struct dirent *d;
    struct stat buf;
    char b[99];
    if (t != NULL) {d = readdir(t);
    lstat(d -> d_name, &buf);
    while (d != NULL){
        if (strcmp (d -> d_name, ".") != 0 && strcmp (d -> d_name, "..") != 0){
            int done = spaces;
            while (done --> 0)
                cout << "_";
            cout << d -> d_name << endl;
            if (S_ISDIR(buf.st_mode)){
                DIR *k = opendir(d -> d_name);
                chdir(d -> d_name);
                checkDirectory(k, spaces + 2);
                chdir("..");
            }
        }

        d = readdir(t);
        lstat(d -> d_name, &buf);
    }}
}


int main (int argc, char**argv){
  //  argv[1] = "/home/petr/test_folder/";
    chdir(argv[1]);
    string path (argv[1]);
    checkDirectory(opendir(path.c_str()), 0);

}
